package com.book.kafka.client.record;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.util.Map;
import java.util.Set;

/**
 * 扩展 ConsumerRecord
 * @param <T>
 */
public class KafkaRecord<T> implements Serializable {

    private static final long serialVersionUID = 2507943044354749991L;

    private String topic;

    private int retryCount;

    private String key;

    private long timestamp;

    @JsonProperty
    private T data;

    @JsonProperty
    private Map<String,String> tags;

    private Set<String> consumerGroupIds;

    public KafkaRecord() {
    }

    public KafkaRecord(String topic, T data) {
        this.topic = topic;
        this.retryCount = 0;
        this.timestamp = System.currentTimeMillis();
        this.data = data;
    }

    public KafkaRecord(String topic, String key, T data) {
        this(topic, data);
        this.topic = topic;
        this.key = key;
        this.data = data;
    }

    public KafkaRecord(String topic, String key, T data, Map<String, String> tags) {
        this(topic, key, data);
        this.key = key;
        this.tags = tags;
    }

    public KafkaRecord(String topic, int retryCount, String key, T data, Map<String, String> tags) {
        this(topic,key, data, tags);
        this.retryCount = retryCount;
    }

    public KafkaRecord(String topic, int retryCount, String key, long timestamp, T data, Map<String, String> tags) {
        this(topic,retryCount, key, data, tags);
        this.timestamp = timestamp;
    }

//    public KafkaRecord(String topic, int retryCount, int partition, String key, long timestamp, T data, Map<String, String> tags) {
//        this(topic,retryCount, key,timestamp, data, tags);
//        this.partition = partition;
//    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public int getRetryCount() {
        return retryCount;
    }

    public void setRetryCount(int retryCount) {
        this.retryCount = retryCount;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public Map<String, String> getTags() {
        return tags;
    }

    public void setTags(Map<String, String> tags) {
        this.tags = tags;
    }

//    public int getPartition() {
//        return partition;
//    }
//
//    public void setPartition(int partition) {
//        this.partition = partition;
//    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Set<String> getConsumerGroupIds() {
        return consumerGroupIds;
    }

    public void setConsumerGroupIds(Set<String> consumerGroupIds) {
        this.consumerGroupIds = consumerGroupIds;
    }

    @Override
    public String toString() {
        return "KafkaRecord{" +
                "topic='" + topic + '\'' +
                ", retryCount=" + retryCount +
                ", key='" + key + '\'' +
                ", timestamp=" + timestamp +
                ", data=" + data +
                ", tags=" + tags +
                ", consumerGroupIds=" + consumerGroupIds +
                '}';
    }
}
